Getting started topic
Getting started
git_engine drives the installed git executable behind typed Dart
contracts. An application chooses one engine where it wires its
dependencies, then programs against interfaces, so the backend stays
replaceable.
Choosing the engine at the composition root
Import package:git_engine/git_engine.dart for the contracts and value
types. Import package:git_engine/process.dart only where the application
constructs the process backend; take from it ProcessGitEngine and
ProcessGitUploadPackService, then hold the constructed objects as
contracts.
ProcessGitEngine implements GitRepositoryManager, GitFileClient and
GitEngineRuntime. Its constructor names the git program, the environment
layered over every command, the Windows long-path setting and the default
command delay. Giving a runner together with any of those options is
refused, because the runner already carries them.
GitEngineRuntime exposes the version facts a backend can report, through
engineVersion and ensureMinimumVersion. A backend without a notion of
version does not expose it. A timeout and an engine below the requested
minimum stay domain refusals of git_engine.dart, so portable code catches
them whatever the backend.
The process backend expects git 2.28 or newer. Its in-memory mergeTree needs git 2.38 or newer; an older installation cannot run that operation and the call is refused.
import 'package:git_engine/git_engine.dart';
import 'package:git_engine/process.dart';
Future<void> main() async {
final ProcessGitEngine engine = ProcessGitEngine(
executable: 'git',
globalEnvironment: <String, String>{'GIT_CONFIG_NOSYSTEM': '1'},
defaultTimeout: const Duration(minutes: 5),
);
final GitRepositoryManager repositories = engine;
final GitFileClient client = engine;
final GitEngineRuntime runtime = engine;
print('${await runtime.engineVersion()}: $repositories $client');
}
Repository hierarchy
The hierarchy classifies a repository by the capabilities it has.
GitRepositoryis the base contract. It assumes no index, no work tree and no filesystem, and every repository exposes its domain accessors: config, remotes, branches, tags, refs, revisions, history, objects, tree patches, merge and reference transactions. It also offers withTemporaryIndex and pruneWorktrees.GitIndexedRepositoryadds an activeGitIndexand the patch operations that compare with or apply to that index. An indexed view derived from a bare repository no longer carries the bare marker.GitFileRepositoryadds disk facts: path, gitDir and the plain files of the git directory throughGitDirectoryFiles.GitWorkingRepositoryimplements bothGitIndexedRepositoryandGitFileRepository. It is the only level with a work tree, adding toplevel, worktree, work-tree patches and in-place merge.GitBareRepositoryadds no operation. It marks a repository without a work tree, so a signature can require one; index work on it goes through an explicit index view.GitFileBareRepositorycombines bare storage with disk access. It is the type a server opens from disk.
Opening and creating
Opening reads the repository kind from git, so a directory that is not a
repository fails immediately. open returns a GitFileRepository whose
precise type is either GitWorkingRepository or GitFileBareRepository;
openWorking and openBare return that precise type when the caller
already knows it.
Creation fixes the type too: init returns a GitWorkingRepository with a
work tree, and initBare returns a GitFileBareRepository. A missing
target directory, missing parents included, is created; an existing empty
directory is used as it stands. A directory that already holds files is
refused before git runs unless allowOccupied hands it to git, which
reinitializes an existing repository and keeps its data. initialBranch
makes HEAD point at the named branch.
Cloning belongs to the client, not the manager: GitFileClient offers
clone and cloneBare. The short runnable examples are
example/local_repository.dart and example/bare_repository.dart.
import 'package:git_engine/git_engine.dart';
import 'package:git_engine/process.dart';
Future<void> main() async {
final GitRepositoryManager repositories = ProcessGitEngine();
final GitWorkingRepository working =
await repositories.init('/srv/project', initialBranch: 'main');
final GitFileRepository opened = await repositories.open(working.path);
final GitFileBareRepository bare =
await repositories.initBare('/srv/project.git', initialBranch: 'main');
print('${opened.runtimeType} ${await bare.gitDir()}');
}
Libraries
- git_engine Getting started
- The package's backend-independent API: engine and repository contracts, value types, error hierarchy and server contracts.
Classes
- GitApplyApplied Getting started
- The patch applied cleanly, to the work tree, the index or both.
- GitApplyConflicted Getting started
- The patch applied with unresolved conflicts.
- GitApplyRefused Getting started
- The patch was refused; nothing was applied.
- GitApplyResult Getting started
- Outcome of applying a patch.
- GitBareRepository Getting started
- A bare GitRepository, typed explicitly.
- GitBranch Getting started
-
A branch: its short name, the commit it points at, whether
HEADpoints at it, and the branch it tracks. - GitBranches Getting started
- Branches of one repository: listing, creating, renaming, deleting and upstream tracking.
- GitCommit Getting started
- A commit object: its tree, parents, identities and message.
- GitConfig Getting started
- Local configuration of one repository.
- GitConfigEntry Getting started
- One key/value pair of a git configuration.
- GitConflictRegion Getting started
- One conflict block found in a work tree file.
- GitDirectoryDrift Getting started
- Differences between a GitDirectorySnapshot and the git directory as it stands now, reported file by file.
- GitDirectoryFiles Getting started
- Plain files of the git directory of one repository: capturing them, reporting what drifted since a capture, and writing a capture back.
- GitDirectorySnapshot Getting started
- A capture of the plain files of a git directory.
- GitEngineRuntime Getting started
- Facts about the version of an engine, independent of any backend.
- GitFileBareRepository Getting started
- A bare GitBareRepository stored on disk.
- GitFileRepository Getting started
- A GitRepository stored on disk.
- GitHistory Getting started
- History of one repository: ancestry, merge bases and path history.
- GitHistoryReader Getting started Compatibility
- Walks the commit graph of one repository.
- GitIdentity Getting started
- Author or committer identity handed to git through environment variables.
- GitIndex Getting started
- Index of one repository: tree writing, unmerged entries and index removal.
- GitIndexedPatches Getting started
- Differences between a tree and the index of one repository, plus applying a patch to the index alone.
- GitIndexedRepository Getting started
- A GitRepository with an active index view.
- GitLogCommit Getting started
- One commit of a history walk: its object name and the complete commit.
- GitLogEntry Getting started
- One commit of a history walk: its object name and its subject.
- GitMerge Getting started
- Merging that needs neither an index nor a work tree: in-memory merges.
- GitMergeCommit Getting started
- A merge commit was created to fold the merged history in.
- GitMergeConflicts Getting started
-
The merge could not be done automatically: the paths it lists were left
with conflicts in the index and the work tree, and the merge stays
in progress (
MERGE_HEAD) until the caller resolves them or gives it up through GitWorkingMerge.abort. - GitMergeFastForward Getting started
- Fast-forward: the current head moved forward onto the merged revision without a new commit.
- GitMergeResult Getting started
- Outcome of a merge, as one of the typed variants.
- GitMergeStopped Getting started
-
A clean, non-fast-forward merge was staged but stopped before committing
(
noCommit): the index holds the merged state andMERGE_HEADmarks the merge as in progress, so the caller can commit it — or give it up throughabort(). - GitMergeTreeResult Getting started
-
Result of an in-memory merge (
git merge-tree): the tree the merge would produce and the paths that conflict in it. - GitMergeUpToDate Getting started
- The merged history was already part of the current head; nothing moved.
- GitObjectReader Getting started Compatibility
- Read access to the objects of one repository, addressed by object name.
- GitObjects Getting started
- Objects, trees and commits of one repository, usable without touching the work tree.
- GitObjectStore Getting started Compatibility
- Read and write access to the objects of one repository.
- GitObjectWriter Getting started Compatibility
- Writes any object to a repository from its type and serialized content.
- GitOid Getting started
- A git object name: a 40-character (SHA-1) or 64-character (SHA-256) hexadecimal string.
- GitPatches Getting started
- Differences between two trees of one repository: changed paths, unified text diffs for display, and portable binary diffs.
- GitRawObject Getting started
- A git object read as stored: its type and its serialized content.
- GitRef Getting started
-
A reference: its full name, e.g.
refs/heads/main, and the object it points at. - GitRefReader Getting started Compatibility
- Read access to the references of one repository.
- GitRefs Getting started
- References of one repository: exact ref reads, symbolic refs and ref updates.
- GitRefTransaction Getting started Compatibility
- A set of reference updates applied together, all or nothing.
- GitRemotes Getting started
- Remotes of one repository and their declaration: listing, adding, removing and renaming remotes, reading and writing their URLs.
- GitRepository Getting started
- Facade over one git repository, whatever its backend.
- GitRepositoryManager Getting started
- Manager role over repositories stored on disk: it opens and creates them.
- GitRepositoryReader Getting started Compatibility
- Read-only view of one repository's stored data.
- GitRepositoryWriter Getting started Compatibility
- Read and write view of the stored data of one repository.
- GitRevisionResolver Getting started Compatibility
-
Interprets git revision expressions (
HEAD~2,main^{tree}…). - GitRevisions Getting started
- Revision expressions of one repository.
- GitStatusEntry Getting started
-
One entry of the work tree status, as reported by
git status. - GitTag Getting started
- An annotated tag object: the object it points at, its name, the tagger and the message.
- GitTagRef Getting started
- A tag reference: its short name, the object the reference names and the final object that object resolves to.
- GitTags Getting started
- Tags of one repository: listing, creating and deleting.
- GitTree Getting started
- A tree object: its object name and the entries it lists.
- GitTreeEntry Getting started
- One entry of a tree object: a blob, a subtree or a gitlink.
- GitUnmergedEntry Getting started
- One stage of a path left unmerged in the index.
- GitWorkingMerge Getting started
- Merging into a work tree: fast-forwards, merge commits, conflicted merges and the in-progress merge state with its abort.
- GitWorkingPatches Getting started
- Differences between the index and the work tree of one repository, plus applying a patch to the work tree.
- GitWorkingRepository Getting started
- A GitFileRepository with a work tree and an active index view.
- GitWorktree Getting started
- Work tree and index of one repository: status, staging, reset, cleaning, checkout, ignore checks and commits.
- ProcessGitEngine Getting started
-
GitRepositoryManager, GitFileClient and GitEngineRuntime that talk to
the real git executable through a
ProcessGitRunner(or any GitRunner handed to the constructor).
Enums
- GitArchiveFormat Getting started
-
Format of an archive streamed by
GitObjects.archive. - GitChangeKind Getting started
- How a path changed between the two sides of a comparison.
- GitFileState Getting started
-
State of a path reported by
git status, on one side of the index. - GitMergeMode Getting started
- Which merges GitWorkingMerge.merge is allowed to perform.
- GitObjectType Getting started
- Kind of an object stored in a git repository.
- GitResetMode Getting started
-
How
git resetmovesHEAD, the index and the work tree. - GitTagFetch Getting started
- Which tags a fetch brings into the repository.